package org.scut.smartgeometry.act.fragment;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import org.scut.smartgeometry.R;
import org.scut.smartgeometry.act.HomePageAct;
import org.scut.smartgeometry.act.adapter.ImageAndTextAdapter;
import org.scut.smartgeometry.ent.ViewCache;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 13-6-4.
 */
public class MainMenuFragment extends ListFragment {

    private HomePageAct homePageAct;

    public MainMenuFragment(HomePageAct homePageAct){
        this.homePageAct = homePageAct;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//        return super.onCreateView(inflater, container, savedInstanceState);
        return inflater.inflate(R.layout.fragment_main_menu, container, false);
    }

    @Override
    public void onStart() {
        super.onStart();
        setListAdapter(new ImageAndTextAdapter(getActivity(), getBtnNames(), getListView()));
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);

        ViewCache viewCache = (ViewCache) v.getTag();
        TextView txtView = viewCache.getTextView();
        String btnName = txtView.getText().toString();

        homePageAct.clickMenu(btnName);
    }

    private List<String> getBtnNames(){
        List<String> btn_names = new ArrayList<String>();
        btn_names.add(getString(R.string.undo));
        btn_names.add(getString(R.string.redo));
        btn_names.add(getString(R.string.color));
        btn_names.add(getString(R.string.style));
        btn_names.add(getString(R.string.background));
        btn_names.add(getString(R.string.clear));
        btn_names.add(getString(R.string.chart));
        btn_names.add(getString(R.string.open));
        btn_names.add(getString(R.string.save));
        btn_names.add(getString(R.string.exit));

        return btn_names;
    }

}
